#include "ParticleComponent.h"
#include "../GameObject/GameObject.h"
#include "../Utils/Timer.h"

using namespace Pantsu;

ParticleComponent::ParticleComponent() 
	:
m_v3Position		( 0.0f, 0.0f, 0.0f ),
m_v3Velocity		( 0.0f, 0.0f, 0.0f ),
m_v3Acceleration	( 0.0f, 0.0f, 0.0f ),
m_v3ForceAcculated  ( 0.0f, 0.0f, 0.0f ),
m_fInverseMass	    ( 1.0f ),
m_fDamping			( 0.99f )
{

}

ParticleComponent::~ParticleComponent() {
}

void ParticleComponent::Update( float i_deltaTime ) {
	
	PerformIntergration( i_deltaTime );
}

void ParticleComponent::PerformIntergration( float i_duration ) {
	
	if ( m_fInverseMass <= 0.0f ) return;
	/*if ( m_v3Position.Y <= -0.01f ) return;*/

	m_v3Position.AddScaledVector( m_v3Velocity, i_duration );
	GetOwner()->GetTransform().SetPosition( m_v3Position );

	Vector3 resultingAcc = m_v3Acceleration;
	resultingAcc.AddScaledVector( m_v3ForceAcculated, m_fInverseMass );
	
	m_v3Velocity.AddScaledVector( resultingAcc, i_duration );

	m_v3Velocity *= m_fDamping;

	ClearAccumulation();
}

void ParticleComponent::AddForce( const Vector3 &i_force ) {
	m_v3ForceAcculated += i_force;
}